package com.kantboot.business.gc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.kantboot.business.gc.domain.dto.BusGcGame18nDTO;
import com.kantboot.business.gc.domain.dto.BusGcGame18nSaveDTO;
import com.kantboot.business.gc.domain.entity.BusGcGameI18n;
import com.kantboot.business.gc.repository.BusGcGameI18nRepository;
import com.kantboot.business.gc.service.IBusGcGameI18nService;
import com.kantboot.util.core.param.PageParam;
import com.kantboot.util.core.result.PageResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BusGcGameI18nServiceImpl implements IBusGcGameI18nService{

    @Resource
    private BusGcGameI18nRepository i18nRepository;

    @Override
    public void addLanguage(BusGcGame18nSaveDTO saveDTO) {
        BusGcGameI18n busGcGameI18n = new BusGcGameI18n();
        BeanUtil.copyProperties(saveDTO,busGcGameI18n);
        busGcGameI18n.setGameId(saveDTO.getTypeId());
        i18nRepository.save(busGcGameI18n);
        log.info("addGameLanguage", saveDTO);
    }

    @Override
    public PageResult getLanguageListByTypeId(PageParam<BusGcGame18nDTO> pageParam) {
        if (pageParam.getData() == null || pageParam.getData().getTypeId() == null) {
            throw new RuntimeException("参数不能为空");
        }
        log.info("getLanguageListByTypeId", pageParam.getData());
        return PageResult.of(i18nRepository.getLanguageListByTypeId(pageParam.getData(), pageParam.getPageable()));
    }

    @Override
    public void deleteLanguage(List<BusGcGame18nSaveDTO> busGcTypeI18nSaveDTOList) {
        List<BusGcGameI18n> busGcGameI18nList = BeanUtil.copyToList(busGcTypeI18nSaveDTOList, BusGcGameI18n.class);
        i18nRepository.deleteAllInBatch(busGcGameI18nList);
    }

}
